package tsi

import (
	watchmessgae "earth/watch_tcp/watch_message"
	"errors"
	"strconv"

	"github.com/sirupsen/logrus"
)

/*
终端心率上传
终端上传：
[DW*334588000000156*len*heart,x]
x 为每分钟心率数据。
实例：[DW*334588000000156*len*heart,100]
代表终端的心率为：100 次/分钟
平台回复：
[DW*334588000000156*0005*heart
*/

// 终端心率上传
type HealthDataHeart struct {
	Heart int // 每分钟心率数据
}

func DealHealthDataHeart(watchMessage *watchmessgae.WatchMessage, deviceID string) error {
	// 校验消息长度
	if len(watchMessage.MessageContentList) < 1 {
		logrus.Error("message is too short:", watchMessage.MessageContentList)
		return errors.New("message is too short")
	}
	// 解析消息内容
	healthDataHeart := &HealthDataHeart{}
	heart, err := strconv.Atoi(watchMessage.MessageContentList[0])
	if err != nil {
		return err
	}
	healthDataHeart.Heart = heart
	return SendEvent(deviceID, healthDataHeart, "temp")
}
